package com.wie.mapper;

import com.wie.pojo.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    /**
     * 新增用户
     * @param username
     * @return
     */
    @Insert("INSERT INTO user(username, password, create_time, update_time) values(#{username}, #{password}, now(), now())")
    void add(@Param("username")String username, @Param("password") String password);

    /**
     * 根据用户名查找用户
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User findByUsername(String username);

    /**
     * 更新用户信息
     * @param user
     */
    @Update("update user set nickname = #{nickname}, email = #{email}, update_time = #{updateTime} where id = #{id}")
    void update(User user);

    /**
     * 更新用户头像
     * @param avatarUrl
     */
    @Update("update user set user_pic = #{avatarUrl}, update_time = now() where id = #{id}")
    void updateAvatar(@Param("avatarUrl") String avatarUrl, @Param("id") Integer id);

    /**
     * 更新用户密码
     * @param password
     * @param id
     */
    @Update("update user set password = #{password}, update_time = now() where id = #{id}")
    void updatePwd(@Param("password") String password, @Param("id") Integer id);
}
